home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / grafica / amhelios / win_meta.h < prev    next >
C/C++ Source or Header  |  1999-01-01  |  6KB  |  227 lines

  1. ////////////////////////////////////////////////////////////
  2. //
  3. //  WIN_META.H - MS-Windows Metafile Class
  4. //
  5. //  Version:    1.03A
  6. //
  7. //  History:    94/08/23 - Version 1.00A release.
  8. //              94/12/16 - Version 1.01A release.
  9. //              95/02/05 - Version 1.02A release.
  10. //              95/07/21 - Version 1.02B release.
  11. //              95/10/11 - Modified Record function to
  12. //                         create temporary file name.
  13. //                       - Changed file_name array length
  14. //                         from 144 to _MAX_PATH.
  15. //                       - Added <stdlib.h> and <string.h>
  16. //                         include directives.
  17. //              96/02/14 - Version 1.02C release.
  18. //              96/04/01 - Version 1.03A release.
  19. //
  20. //  Compilers:  Microsoft Visual C/C++ Professional V1.5
  21. //              Borland C++ Version 4.5
  22. //
  23. //  Author:     Ian Ashdown, P.Eng.
  24. //              byHeart Software Limited
  25. //              620 Ballantree Road
  26. //              West Vancouver, B.C.
  27. //              Canada V7S 1W3
  28. //              Tel. (604) 922-6148
  29. //              Fax. (604) 987-7621
  30. //
  31. //  Copyright 1994-1996 byHeart Software Limited
  32. //
  33. //  The following source code has been derived from:
  34. //
  35. //    Ashdown, I. 1994. Radiosity: A Programmer's
  36. //    Perspective. New York, NY: John Wiley & Sons.
  37. //
  38. //  It may be freely copied, redistributed, and/or modified
  39. //  for personal use ONLY, as long as the copyright notice
  40. //  is included with all source code files.
  41. //
  42. ////////////////////////////////////////////////////////////
  43.  
  44. #ifndef _WIN_META_H
  45. #define _WIN_META_H
  46.  
  47. /*
  48. #include <windows.h>
  49. #include <stdio.h>
  50. #include <stdlib.h>
  51. #include <string.h>
  52.  
  53. class WinMetaFile       // MS-Windows metafile
  54. {
  55.   private:
  56.     char file_name[_MAX_PATH];  // File name
  57.     BOOL file_flag;             // File name flag
  58.     HDC hmdc;                   // Device context handle
  59.     HMETAFILE hmf;              // Metafile handle
  60.  
  61.   public:
  62.     WinMetaFile()
  63.     {
  64.       *file_name = '\0';
  65.       file_flag = FALSE;
  66.       hmdc = NULL;
  67.       hmf = NULL;
  68.     }
  69.  
  70.     ~WinMetaFile() { Erase(); }
  71.  
  72.     void Erase()        // Erase metafile
  73.     {
  74.       Stop();   // Stop recording
  75.  
  76.       if (hmf != NULL)
  77.       {
  78.         DeleteMetaFile(hmf);    // Delete metafile handle
  79.         hmf = NULL;
  80.       }
  81.  
  82.       if (file_flag == TRUE)
  83.       {
  84.         unlink(file_name);      // Remove metafile
  85.         file_flag = FALSE;
  86.       }
  87.     }
  88.  
  89.     // Play metafile to display device
  90.     void Play( HWND hwnd, int win_w, int win_h, int view_w,
  91.         int view_h )
  92.     {
  93.       HDC hdc;          // Device context handle
  94.       PAINTSTRUCT ps;   // Paint structure
  95.  
  96.       if (hmf != NULL)
  97.       {
  98.         hdc = BeginPaint(hwnd, &ps);
  99.  
  100.         // Initialize window-to-viewport mapping mode
  101.         SetMapMode(hdc, MM_ISOTROPIC);
  102.         SetWindowExtEx(hdc, win_w, win_h, NULL);
  103.         SetViewportExtEx(hdc, view_w, -view_h, NULL);
  104.         SetViewportOrgEx(hdc, 0, view_h, NULL);
  105.  
  106.         PlayMetaFile(hdc, hmf);
  107.  
  108.         EndPaint(hwnd, &ps);
  109.       }
  110.     }
  111.  
  112.    // Add polygon draw instruction to metafile
  113.     BOOL Polygon( POINT *vertex, int num )
  114.     { return ::Polygon(hmdc, vertex, num); }
  115.  
  116.     BOOL Record( BOOL fflag )   // Start metafile recording
  117.     {
  118.       int len;  // Directory name length
  119.  
  120.       Erase();  // Erase previous metafile
  121.  
  122.       if (fflag == TRUE)
  123.       {
  124.         // Get Windows directory
  125.         len = GetWindowsDirectory(file_name, _MAX_PATH);
  126.  
  127.         // Append '\' character (if necessary)
  128.         if (file_name[len - 1] != '\\')
  129.           lstrcat(file_name, "\\");
  130.  
  131.         // Append temporary metafile file name
  132.         lstrcat(file_name, "METAFILE.TMP");
  133.  
  134.         file_flag = TRUE;
  135.  
  136.         // Create file-based metafile
  137.         if ((hmdc = CreateMetaFile(file_name)) == NULL)
  138.           return FALSE;
  139.       }
  140.       else
  141.       {
  142.         // Create memory-based metafile
  143.         if ((hmdc = CreateMetaFile(NULL)) == NULL)
  144.           return FALSE;
  145.       }
  146.  
  147.       // Select transparent brush for polygon fill
  148.       SelectObject(hmdc, GetStockObject(NULL_BRUSH));
  149.  
  150.       return TRUE;
  151.     }
  152.  
  153.     BOOL Stop()         // Stop metafile recording
  154.     {
  155.       if (hmdc != NULL)
  156.       {
  157.         hmf = CloseMetaFile(hmdc);
  158.         hmdc = NULL;
  159.       }
  160.       return (hmf != NULL) ? TRUE : FALSE;
  161.     }
  162. };
  163. */
  164.  
  165. #include <proto/graphics.h>
  166. #include <proto/intuition.h>
  167.  
  168. #include <stdio.h>
  169. #include <stdlib.h>
  170. #include <string.h>
  171.  
  172. class WinMetaFile       // MS-Windows metafile, Amigaized.
  173. {
  174.     public:
  175.         WinMetaFile(struct Window *win_arg,struct DrawInfo *dri_arg,int left_arg,int top_arg)
  176.         {
  177.             win = win_arg;
  178.             dri = dri_arg;
  179.             left = left_arg;
  180.             top = top_arg;
  181.         }
  182.         ~WinMetaFile() { }
  183.         void Erase()
  184.         {
  185.             ;
  186.         }
  187.         BOOL Polygon(POINT *vertex, int num)
  188.         {
  189.             int t;
  190.             ULONG oldcol;
  191.  
  192.             oldcol = GetAPen(win->RPort);
  193.             SetAPen(win->RPort,dri->dri_Pens[col]);
  194.  
  195.             Move(win->RPort,left+vertex[0].x,top+vertex[0].y);
  196.             for(t=1; t<num; t++)
  197.             {
  198.                 Draw(win->RPort,left+vertex[t].x,top+vertex[t].y);
  199.             }
  200.             Draw(win->RPort,left+vertex[0].x,top+vertex[0].y);
  201.  
  202.             SetAPen(win->RPort,oldcol);
  203.  
  204.             return TRUE;
  205.         }
  206.         BOOL Record(BOOL fflag)
  207.         {
  208.             SetColor(TEXTPEN);
  209.             return TRUE;
  210.         }
  211.         BOOL Stop()
  212.         {
  213.             return TRUE;
  214.         }
  215.         void SetColor(int col_arg)
  216.         {
  217.             col = col_arg;
  218.         }
  219.     protected:
  220.         struct Window *win;
  221.         struct DrawInfo *dri;
  222.         int top,left;
  223.         int col;
  224. };
  225. #endif
  226.  
  227.